#include "chartview.h"
#include <Qt>
#include <QSplitter>
#include <QMessageBox>
#include <QScrollBar>

ChartView::ChartView(QGraphicsScene *scene)
    :QGraphicsView(scene)
{
    this->setFocusPolicy(Qt::NoFocus);
    this->setDragMode(QGraphicsView::ScrollHandDrag);
    this->setAlignment(Qt::AlignLeft);
    //this->setTransformationAnchor(QGraphicsView::AnchorUnderMouse);

}

void ChartView::zoomin()
{
    matrix.scale(2,1);
    this->setMatrix(matrix);
}
void ChartView::zoomout()
{
    matrix.scale(0.5,1);
    this->setMatrix(matrix);
}
void ChartView::move(int mx)
{
    this->horizontalScrollBar()->setValue(mx);
}



ChartSplitter::ChartSplitter(QWidget *parent)
    :QSplitter(Qt::Vertical,parent)
{
    setFocusPolicy(Qt::StrongFocus);
}

void ChartSplitter::keyPressEvent(QKeyEvent *keyZoom)
{
    if (keyZoom->key()==Qt::Key_Up)
    {
        emit zoomin();
        //QMessageBox::about(NULL, "About", "About this <font color='red'>application</font>");
    }
    else if (keyZoom->key()==Qt::Key_Down)
    {
        emit zoomout();
        //QMessageBox::about(NULL, "About2", "About this <font color='red'>application</font>");
    }
    keyZoom->accept();
}
void ChartSplitter::wheelEvent(QWheelEvent *wheelZoom)
{
    if (wheelZoom->angleDelta().y() > 0)
    {
        //QMessageBox::about(NULL, "About", "About this <font color='red'>application</font>");
        emit zoomin();
    }
    else if (wheelZoom->angleDelta().y() < 0)
    {
        //QMessageBox::about(NULL, "About2", "About this <font color='red'>application</font>");
        emit zoomout();
    }
    wheelZoom->accept();
}
